package service;

import lombok.extern.slf4j.Slf4j;

import java.io.IOException;
import java.io.InputStream;
import java.util.Objects;
import java.util.Properties;


/**
 * @program: refactor-sepal
 * @description:
 * @author: XuYifei
 * @create: 2025-02-19
 */


@Slf4j
public class ConfigService {

    public static Properties config_properties = new Properties();
    private static final String CONFIG_PROPERTIES_PATH = "config.properties";

    static {
        try (InputStream input = ConfigService.class.getClassLoader().getResourceAsStream(CONFIG_PROPERTIES_PATH)) {
            if (input == null) {
                log.error("Sorry, unable to find {}", CONFIG_PROPERTIES_PATH);
            }
            config_properties.load(input);
        } catch (IOException ex) {
            log.error("IOException occurred while loading properties file", ex);
        }
    }

    public static String getProperty(String key) {
        return config_properties.getProperty(key);
    }

    public static String getConfig(String key){
        return getPath(getProperty(key));
    }

    public static String getPath(String path){
        return Objects.requireNonNull(ConfigService.class.getClassLoader().getResource(path)).getPath();
    }

    public static void main(String[] args) {
        log.info("ConfigService started");
    }
}
